//
//  SectionCell.m
//  NJUSTHelper
//
//  Created by 郑越辉 on 2017/9/21.
//  Copyright © 2017年 njust. All rights reserved.
//

#import "SectionCell.h"
#import "Define.h"
@interface SectionCell()
@property (nonatomic, strong) NSArray *startSectionTimeArray;
@property (nonatomic, strong) NSArray *endSectionTimeArray;
@property (nonatomic, strong) NSArray *sectionNumArray;
///左侧时间
@property (weak, nonatomic) IBOutlet UILabel *startTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *sectionNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *endTimeLabel;

///右侧更多按钮
@property (weak, nonatomic) IBOutlet UIButton *moreButton;

///居中课表内容
@property (weak, nonatomic) IBOutlet UIView *scheduleBodyView;
@property (weak, nonatomic) IBOutlet UILabel *courseTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *placeImageView;
@property (weak, nonatomic) IBOutlet UILabel *placeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *scoreImageView;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UIImageView *teacherImageView;
@property (weak, nonatomic) IBOutlet UILabel *teacherLabel;
@property (weak, nonatomic) IBOutlet UIImageView *timeImageView;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;


@end


@implementation SectionCell
-(NSArray *)startSectionTimeArray {
    if(!_startSectionTimeArray){
        _startSectionTimeArray =[NSArray arrayWithObjects:@"8:00", @"10:40", @"14:00", @"15:50", @"19:00", nil];
    }
    return _startSectionTimeArray;
}
-(NSArray *)endSectionTimeArray{
    if(!_endSectionTimeArray){
        _endSectionTimeArray =[NSArray arrayWithObjects:@"10:25", @"12:10", @"15:40", @"18:15", @"21:25", nil];
    }
    return _endSectionTimeArray;
}
-(NSArray *)sectionNumArray {
    if(!_sectionNumArray){
        _sectionNumArray =[NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
    }
    return _sectionNumArray;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.moreButton setHidden:YES];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

-(void)setSectionSchedulleArray:(NSMutableArray *)sectionSchedulleArray {
    
    if([sectionSchedulleArray count] == 0){
        for (UIView *view in [self.scheduleBodyView subviews])
        {
            [view removeFromSuperview];
        }
        [self.moreButton setHidden:YES];
    }
    
    _sectionSchedulleArray = sectionSchedulleArray;
    ScheduleModel *currentShowModel = nil;
    for (ScheduleModel *temp in sectionSchedulleArray) {
        ///优先顺序
        ///当前周
        if(CheckBit(temp.weekNum, self.weekNum)){
            currentShowModel = temp;
            break;
        }
        ///将来要上的课
        if(temp.weekNum > SetBitTo_1(0, self.weekNum)){
            currentShowModel = temp;
        }
        ///上过的课
        if(!currentShowModel){
            currentShowModel = temp;
        }
    }
    if(currentShowModel) {
        [self setScheduleContentWithModel:currentShowModel];
    }else{
        for (UIView *view in [self.scheduleBodyView subviews])
        {
            [view removeFromSuperview];
        }
    }
    if([sectionSchedulleArray count] > 1){
        [self.moreButton setHidden:NO];
        
    }else{
        [self.moreButton setHidden:YES];
    }
    
    
}
-(void)setSectionNum:(NSInteger)sectionNum {
    _sectionNum = sectionNum;
    self.startTimeLabel.text = [self.startSectionTimeArray objectAtIndex:sectionNum];
    self.endTimeLabel.text = [self.endSectionTimeArray objectAtIndex:sectionNum];
    self.sectionNumLabel.text = [self.sectionNumArray objectAtIndex:sectionNum];
}
-(void)setScheduleContentWithModel:(ScheduleModel*)model {
    if([model.courseGroup length] == 0){
        self.courseTitleLabel.text = model.courseName;
    }else{
        self.courseTitleLabel.text = [model.courseName stringByAppendingString:[NSString stringWithFormat:@"-%@", model.courseGroup]];
    }
    
    self.placeLabel.text = [NSString nullString:model.placeStr RepleseWith:@"[教室未知]"];
    self.scoreLabel.text = [NSString stringWithFormat:@"%.1f 学分",model.score];
    self.teacherLabel.text = model.teacher;
    self.timeLabel.text = model.timeStr;
    
    if(CheckBit(model.weekNum, self.weekNum)){
        ///当前周
        self.courseTitleLabel.textColor = Main_Navigation_Color;
        self.placeLabel.textColor = SCHEDULE_CELL_COLOR;
        self.scoreLabel.textColor = SCHEDULE_CELL_COLOR;
        self.teacherLabel.textColor = SCHEDULE_CELL_COLOR;
        self.timeLabel.textColor = SCHEDULE_CELL_COLOR;
        [self.placeImageView setImage:[UIImage imageNamed:@"schedule_cell_place"]];
        [self.scoreImageView setImage:[UIImage imageNamed:@"schedule_cell_score"]];
        [self.teacherImageView setImage:[UIImage imageNamed:@"schedule_cell_teacher"]];
        [self.timeImageView setImage:[UIImage imageNamed:@"schedule_cell_time"]];
    }
    else{
        ///非当前周
        self.courseTitleLabel.textColor = SCHEDULE_CELL_DISABLE_COLOR;
        self.placeLabel.textColor = SCHEDULE_CELL_DISABLE_COLOR;
        self.scoreLabel.textColor = SCHEDULE_CELL_DISABLE_COLOR;
        self.teacherLabel.textColor = SCHEDULE_CELL_DISABLE_COLOR;
        self.timeLabel.textColor = SCHEDULE_CELL_DISABLE_COLOR;
        [self.placeImageView setImage:[UIImage imageNamed:@"schedule_cell_place_disable"]];
        [self.scoreImageView setImage:[UIImage imageNamed:@"schedule_cell_score_disable"]];
        [self.teacherImageView setImage:[UIImage imageNamed:@"schedule_cell_teacher_disable"]];
        [self.timeImageView setImage:[UIImage imageNamed:@"schedule_cell_time_disable"]];
    }
}
- (IBAction)moreButtonAction:(UIButton *)sender {
    
    
}


@end
